import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 于金鹏
 * @Date 2024/12/11 14:22
 * @Package yujinpeng
 */
@WebServlet("/httpstudent")
public class StudentHttpServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().write("<h1>yjp</h1>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println(req.getHeader("Content-Type"));
        System.out.println(req.getParameter("name"));
        resp.setStatus(200);
        resp.setContentType("application/json;charset=utf-8");
        resp.setCharacterEncoding("utf-8");

        resp.getWriter().write("{\"name\":\"张三\"}");
    }

}
